include(${CMAKE_CURRENT_LIST_DIR}/../cmake/QtCreatorIDEBranding.cmake)

set(CPACK_PACKAGE_NAME ${IDE_CASED_ID})
set(CPACK_PACKAGE_VENDOR "The Qt Company Ltd")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${IDE_DISPLAY_NAME})
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${IDE_ID})
set(CPACK_VERBATIM_VARIABLES YES)

#set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_LIST_DIR}/Description.txt)
#set(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_LIST_DIR}/Welcome.txt)
#set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_LIST_DIR}/Readme.txt)

# WIX needs a license file ending with .txt
file(CREATE_LINK
  ${CMAKE_CURRENT_LIST_DIR}/../LICENSE.GPL3-EXCEPT
  ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.GPL3-EXCEPT.txt
  COPY_ON_ERROR)
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.GPL3-EXCEPT.txt)

set(CPACK_PACKAGE_CONTACT "None")
set(CPACK_THREADS 4)
set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
set(CPACK_DEBIAN_COMPRESSION_TYPE lzma)

# Make CMAKE_INSTALL_DEFAULT_COMPONENT_NAME the first component to install
get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS)
list(REMOVE_ITEM CPACK_COMPONENTS_ALL ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
list(REMOVE_ITEM CPACK_COMPONENTS_ALL libraries) # empty component, breaks WIX
list(REMOVE_ITEM CPACK_COMPONENTS_ALL DebugInfo) # exclude the huge debug info
list(PREPEND CPACK_COMPONENTS_ALL ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})

set(CPACK_COMPONENT_Dependencies_HIDDEN TRUE)

if (APPLE)
  set(CPACK_INSTALL_PREFIX "/")
endif()

if (WIN32)
  set(CPACK_PACKAGE_INSTALL_DIRECTORY ${IDE_ID}-${CMAKE_PROJECT_VERSION})
else()
  set(CPACK_SET_DESTDIR ON)
  set(CPACK_STRIP_FILES ON)

  if (NOT APPLE)
    set(CPACK_INSTALL_CMAKE_PROJECTS
        "${CMAKE_BINARY_DIR};${IDE_CASED_ID};ALL;/"
        "${CMAKE_BINARY_DIR};Dependencies;Dependencies;/"
    )
  endif()
endif()

# NSIS-specific configuration
set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_LIST_DIR}/../src/app/qtcreator.ico")
set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_LIST_DIR}/../src/app/qtcreator.ico")
set(CPACK_NSIS_INSTALLED_ICON_NAME "${IDE_APP_PATH}\\${IDE_APP_TARGET}.exe")
set(CPACK_NSIS_DISPLAY_NAME "${IDE_DISPLAY_NAME} ${CMAKE_PROJECT_VERSION}")
set(CPACK_NSIS_PACKAGE_NAME "${IDE_DISPLAY_NAME} ${CMAKE_PROJECT_VERSION}")
set(CPACK_NSIS_COMPRESSOR "/SOLID lzma\n  SetCompressorDictSize 64")
set(CPACK_NSIS_INSTALL_ROOT "C:\\Qt")
set(CPACK_NSIS_MUI_FINISHPAGE_RUN "${IDE_APP_TARGET}")
set(CPACK_NSIS_CREATE_ICONS_EXTRA
   "CreateShortCut '$SMPROGRAMS\\$STARTMENU_FOLDER\\${IDE_DISPLAY_NAME} ${CMAKE_PROJECT_VERSION}.lnk' '$INSTDIR\\${IDE_APP_PATH}\\${IDE_APP_TARGET}.exe' "
)
set(CPACK_NSIS_MANIFEST_DPI_AWARE ON)

# WIX-specific configuration
set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_LIST_DIR}/../src/app/qtcreator.ico")
set(CPACK_WIX_UPGRADE_GUID "E6A093A5-83DE-47FA-B669-1DE0102BE92A")
set(CPACK_WIX_LIGHT_EXTRA_FLAGS "-dcl:high") # set high compression

include(CPack)
